<?php
include_once "xAP-functions/webincludes.php";
echo webpageheader();

$zenith=90+50/60;
$now=date("Y-m-d H:i:s");


$sql="select * from xAP_Weather_Source
where Active=1
order by Location
";
$results=dbquery($sql);

$sql="select * from xAP_Weather_Forecast
order by ForecastID
";
$forecast=dbquery($sql);






//display
echo "<Table width=100%>";
foreach($results as $row){
		$sunrise=date_sunrise(time(),SUNFUNCS_RET_STRING,$row["lat"],$row["lng"],$zenith,1);
		$sunset=date_sunset(time(),SUNFUNCS_RET_STRING,$row["lat"],$row["lng"],$zenith,-1);
		$now=date("H:i:s");
		//day or night
		$timeofday="night";
		$iconprefix="night";
		if(strtotime($sunrise)<strtotime($now) && strtotime($sunset)>strtotime($now)){
				$timeofday="day";
				$iconprefix="";
		}	
echo "<tr>
<TD><img src='images/".$iconprefix.$row["Icon"].".jpg' height=128 width=128></td>";

			
echo "
<TD class='normaltext'>
<span class='boldtext'>".$row["Location"]."</span><BR>
<span class='normaltext'>".$row["Temp"]."&deg;C</span><BR>
<span class='normaltext'>".$row["WindSpeed"]."mph ".$row["WindDirection"]."</span><BR>
<span class='normaltext'>".$row["Pressure"]."mB ".$row["Humidity"]."%</span><BR>
<span class='normaltext'>".$sunrise." ".$sunset." </span><BR>
<span class='normalsmalltext'>".$row["DateStamp"]."</span><BR>
<span class='normaltext'><a href='archive_current.php?id=".$row["SourceID"]."'>Log</a></span><BR>
</td>";
foreach($forecast as $value){
	if($value["SourceID"]==$row["SourceID"]){
		echo "<TD class='normaltext'>
		<span><img src='images/".$iconprefix.$value["Icon"].".jpg' height=64 width=64></span><BR>
		<span class='normaltext'>".$value["TempMin"]."&deg;C &gt; ".$value["TempMax"]."&deg;C</span><BR>
		<span class='normaltext'>".$value["WindSpeed"]."mph ".$value["WindDirection"]."</span><BR>
		<span class='normaltext'>".$value["DayName"]."</span>		
		</TD>";
	
	}
}

echo "
</tr>

<tr bgcolor='#aaaaaa'><td colspan=100></td></tr>
";

}
echo "</table>";

echo webpagefooter();
?>